package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.ShopBean;

import java.util.List;

/**
 * Created by mac on 2018/1/2.
 */

public class ShopAdapter extends RecyclerView.Adapter <ShopAdapter.MyViewHolder>{

    private Context context;
    private List<ShopBean.DataBean> goods;


    public ShopAdapter(Context context, List<ShopBean.DataBean> goods) {
        this.context = context;
        this.goods = goods;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.shop_item,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        final ShopBean.DataBean dataBean  = goods.get(position);

        Glide.with(context).load(dataBean.getImg()).into(holder.shop_img);
        holder.shop_name.setText(dataBean.getStoreName());
    }



    @Override
    public int getItemCount() {
        return goods==null?0:goods.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView shop_name;
        private ImageView shop_img;


        public MyViewHolder(View itemView) {
            super(itemView);
            shop_name = (TextView) itemView.findViewById(R.id.shopadapter_shopname);
            shop_img = (ImageView) itemView.findViewById(R.id.shopadapter_shopimg);
        }
    }


}
